RELEASED TO THE PUBLIC DOMAIN BY CODEWORKS DEVELOPMENT, DECEMBER 1993.
You may freely copy, distribute and reuse the code in this example. Codeworks disclaims any warranty of any kind, expressed or implied, as to its fitness for any particular use.
Info: Implementation of the Manager class. Manager acts as the central object for the DynaDoodle application, and is NXApp's delegate. It coordinates the loading of doodle modules and the selection of the current doodle. It also forwards some graphical control methods to the current doodle.
In its implementation, Manager is tied explicitly to DoodleModule and Doodle. It would have been possible to create a version with far less dependence on these classes. Such a version would have made it easier to use Manager in other projects, but I felt that this would have obscured the concepts and constructs of dynamic loading. I hope that once you understand the basic structure, you can easily adapt it to your own uses.
Info: Applicaton delegate method, informs Manager that NXApp has been initialized. Manager uses this opportunity to create the Bundles, fill a PopUpList with the available Doodles, and set the current Doodle to a default setting.
Info: Creates full set of Bundles and adds to bundleList. Searches for modules with extension MODULEEXTENSION. Looks in LIBRARYSUBPATH within Library directories and then app package. If doLoad = YES, will load modules too. Otherwise, just creates Bundles, defers loading of modules until each is needed.
Info: Creates set of Bundles for modules in given directory. If doLoad = YES, will load modules too. Otherwise, just creates Bundles, defers loading of modules until each is needed.
Note that Bundles are added to the List in the order that their module packages are found by readdir(), which can be unpredictable. Depending on your needs, you may want to adjust this order now. See fillCurrentDoodlePopUpList below.
Info: Fills a PopUpList with the names of the available Doodles. Also sets tags of entries for easy identification.
In a real program, you might want to alphasort the list of module names before putting them into the PopUpList. Even better is to give the user some way to set the order that the modules are listed. This makes the most sense when the selection control is something like a Matrix of ButtonCells. Another bonus option is to let the user add and subtract modules that the program presents. See createBundlesForDirectory:loadModules: above.
Info: Sets the current Doodle to a default setting when the program launches. Also synchronizes the PopUpList with this choice.
Taking the easy way out, this just gets the Doodle at index 0 in bundleList. A real program would allow the user to set the preferred module to appear at launch time.
Info: Sets currentDoodle to the supplied Doodle. To do this, it sets the foreground and background colors of the Doodle to the current settings, then puts it into the doodleBox.